Imports TreeCreeper01Interfaces

Public Module ObjectFactory

    Friend Const IndexOfFirstDataRow As Integer = 2


    Private Function InferSourceFileType(ByVal FileName As String) As eSourceFileType

        Dim SourceFileType As eSourceFileType

        If FileName.ToLower.EndsWith(".csv") Then
            SourceFileType = eSourceFileType.eftCSV
        Else
            Throw New Exception("Data file '" & FileName & "' should be .CSV file!")
        End If

        Return SourceFileType

    End Function


    Public Function CreateNonSpatialDataAgent(ByVal FileName As String, ByVal DoOpenTheWorksheet As Boolean, Optional ByVal TaxonomicOverrideFilename As String = "") As IDataAgentNonSpatial

        Dim SourceFileType As eSourceFileType
        Dim DataAgent As IDataAgentNonSpatial

        SourceFileType = InferSourceFileType(FileName)

        DataAgent = Nothing

        If SourceFileType = eSourceFileType.eftCSV Then
            DataAgent = New cCSVDataAgentForNonSpatialData(FileName, TaxonomicOverrideFilename)
        End If

        Return DataAgent

    End Function

    Public Function CreateSpatialDataAgent(ByVal FileName As String, ByVal DoOpenTheWorksheet As Boolean, Optional ByVal TaxonomicOverrideFilename As String = "") As IDataAgentSpatial

        Dim SourceFileType As eSourceFileType
        Dim DataAgent As IDataAgentSpatial

        SourceFileType = InferSourceFileType(FileName)

        DataAgent = Nothing

        If SourceFileType = eSourceFileType.eftCSV Then
            DataAgent = New cCSVDataAgentForSpatialData(FileName, TaxonomicOverrideFilename)
        End If

        Return DataAgent

    End Function

End Module
